﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Atelcom.Core.DataContext
{
    public partial class Atelcom_Entities
    {
        public static Atelcom_Entities GetEntity()
        {
            if (!HttpContext.Current.Items.Contains("Atelcom"))
            {
                Atelcom_Entities db = new Atelcom_Entities();
                HttpContext.Current.Items.Add("Atelcom", db);
                HttpContext.Current.ApplicationInstance.EndRequest += new EventHandler(ApplicationInstance_EndRequest);
            }
            return (Atelcom_Entities)HttpContext.Current.Items["Atelcom"];
        }

        static void ApplicationInstance_EndRequest(object sender, EventArgs e)
        {
            if (HttpContext.Current.Items.Contains("Atelcom"))
                ((Atelcom_Entities)HttpContext.Current.Items["Atelcom"]).Dispose();
        }
    }
}
